// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import store from './store'
import api from './service'

import Loading from '@/components/Loading'
import { Toast } from 'mint-ui'

Vue.prototype.$toast = Toast
import 'mint-ui/lib/toast/style.css'

import { sync } from 'vuex-router-sync'
sync(store, router)

import VueAwesomeSwiper from 'vue-awesome-swiper'
Vue.use(VueAwesomeSwiper)

router.afterEach(route => {
  try {
    if (route.name === 'Home' || route.name === 'List') {
      window.sendBack(false)
    } else {
      window.sendBack(true)
    }
  } catch (e) {

  }
})

Vue.component('Loading', Loading)

Vue.config.productionTip = false
Vue.prototype.$api = api
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  template: '<App/>',
  components: { App }
})

window.setUserInfo = (...info) => {
  if (info.length === 3) {
    store.dispatch('global/setInfo', {user_id: info[0], source_app: info[1], idfa: info[2]})
  }
}

window.skip = (url) => {
  if (url && url.indexOf('http') > -1) {
    router.push({ name: 'IFrame', params: {url} })
  }
}
